Today's learning efficiency is relatively high. After analyzing Rio, I learned the RedisObject file, which is about converting and creating RedisObject. Most of the methods are very similar. List the long API list: * ------------ API --------------------- * robj * createObject (intty
Today's learning efficiency is relatively high. After analyzing Rio, I learned the RedisObject file, which is about converting and creating RedisObject. Most of the metho
Redis source code analysis () --- create and release a redisObject object, redisredisobject
Today's learning efficiency is relatively high. After analyzing Rio, I learned the RedisObject file, which is about converting and creating RedisObject. Most of the methods are very similar. List the long API list:
/* ------------ API ------------------- */robj * createObject (int type, void * ptr)/* method for creating a
Today's study is more efficient. The Rio analysis over, learning another way between redisobject files, just want to say redisobject some build and convert. are very similar to each other. Lists the long list of APIs inside:/*------------API---------------------*/robj *createobject (int type, void *ptr)/* Initial Create RobJ object method, followed by creation method similar to this */
, that is, the operation class used to implement command processing between the Client and Server, store dict and ziplist into robj in the form of robj, and perform various conversions to implement command operations. Avoiding the complex structure of the struct, it encapsulates the operation class of the struct. Today I am talking about t_hash, which is the dict hash dictionary, and the conversion between
Tags: in-memory database Rediswe know that the Redis database, as a memory database, is similar to memcached, where the basic operations are stored in a memory buffer until the data in the buffer is full and persisted to disk. Today, I focused on working with the in-memory database for Redis. Compared to normal data manipulation, there is nothing particularly more to do with some of the other operations. Here are some of the APIs I've sorted out:/*------------------------------------------------
this member
unsigned lru:lru_bits; * * LRU time (relative to Server.lruclock) *
//reference count
int refcount;
Pointer to the underlying data implementation, pointing to a dict dictionary structure
void *ptr;
} robj;
For example, we create a user:info hash key, which has three fields, namely name,sex,passwd.
127.0.0.1:6379> hmset user:info name Mike sex male passwd 123456
OK
127.0.0.1:6379> hgetall user:info
Let's take this as
whenever a linked list is inserted into the database, the newly inserted list is judged to be blocked by the client, and if so, the blocked client is removed and the newly inserted list element is sent to the client. The client is thus unblocked.
Look at the data structure and server and client-related properties first
Blocking state typedef struct BLOCKINGSTATE {/* Generic fields. */mstime_t timeout; /* Timeout Time * * * redis_block_list/* dict *keys; /* The keys we are waiting to te
Database Operations1) Redis is all made up of key and value values, and additions and deletions to the database are based on the mapping of keys to the hash slot and then through the hash slot for a one-way chain traversal to find the value and the specific key.Also in view of the master wrote the source code can be said to be a good reference:All the operations here have been subject to source code references are Zai REDIS/SRC/DB.C under the following:CheckRobJ *lookupkey (Redisdb *db,
The last time I only analyzed the parts of the Redis network part of the code, today I took networking's code implementation part also learned, networking's code more emphasis is the operation of client clients. The method operation inside the Addreply () series is the main part. This series of light-and-light methods should occupy half the number of APIs. I have divided the API into 3 parts:/*------------API----------------------*/void *dupclientreplyvalue (void *o)/* Copy value one copy of */i
catAppendOnlyGenericCommand (sds dst, int argc, robj ** argv) /* encapsulate parameters based on the input string and output the */sds catAppendOnlyExpireAtCommand (sds buf, struct redisCommand * cmd, robj * key, robj * seconds) again) /* convert all expired commands to PEXPIREAT, and convert the time to absolute time */void feedAppendOnlyFile (struct redisComma
read first), record the number of key space hits or missesAfter the key is read, the LRU of the update keyThe expiration key is deleted when read is found to have expiredIf a client uses the watch command to monitor key, it is marked as dirty after modificationAfter modification, 1 is added to the Dirty key counter for persistence and replicationIf the database notification is turned on, the change will send the corresponding notification RobJ *looku
Redis source code analysis (30th) --- pubsub publish and subscribe Mode
Today I learned the term "Publish and subscribe mode" in Redis, which was first introduced to JMS (Java Message Service) java Message Service. I subscribe to these types of messages. Only when these types of messages are broadcast and sent Will I filter other messages directly, this ensures an efficient transmission efficiency. Next, let's take a look at how Redis achieves this publishing and subscription model. Let's take a
subscriptions to the client , including channels + patterns pipe and Mode/int Pubsubsubscribechannel (redisclient *c, RobJ *channel)/* Client subscribe to a channel pipe/INT Pub Subunsubscribechannel (redisclient *c, robj *channel, int notify)/* unsubscribe from the channel/int pubsubsubscribepattern in the client ( Redisclient *c, RobJ *pattern)/* Client client
block */ssize_t aofrewritebufferwrite (int fd)/* is written to the file with the buffer contents of the save memory, as well as a chunked block write */void aof_ Background_fsync (int fd)/* Open background thread for file synchronization operation */void stopappendonly (void)/* Stop append Data operation, here is a command mode */int startappendonly ( void)/* Open Append mode */void flushappendonlyfile (int force)/* Refresh the contents of the buffer to disk */sds Catappendonlygenericcommand (
April 1, Redis3.0-stable officially released. The cluster model is introduced, and several optimizations are made at the same time. This article, from the source level of 3.0 and 2.8.19 comparison, detailed explanation of the optimization details. Due to limited ability and time, I will only compare the source parts I have read, and not involve cluster related content. 1. Embedded String
Reduce memory reading due to cache miss, further improve cache hit rate, in some scenarios, a large increase
April 1, Redis3.0-stable officially released. A long-lost cluster model was introduced, and several optimizations were carried out at the same time. In this article, we compare 3.0 and 2.8.19 from the source level and explain the details of optimization in detail. Due to the limited capacity and time, I will only compare the source parts I have read, and do not involve cluster related content.1. Embedded StringReduces memory reads due to cache miss, further increases cache hit rate and, in some
/
* ordered set */
typedef struct ZSET {
dict *dict;/* Storage
ordered collection Operations
Add Data
The command Zadd enables you to add an ordered collection to the database, which is implemented by the Zaddgenericcommand function. The function will first parse the command options, command arguments, and then depending on whether the underlying is implemented by a skip table or a compression list implementation, is the interface that calls both
/* Add data to an ordered collection */vo
waste unnecessary CPU time on other expire key.
2, but this policy is not friendly to memory, a key has expired, but it will not be deleted before it is manipulated, still occupy the memory space. If you have a large number of expired keys but are rarely accessed, it can cause a lot of wasted memory space. The expireifneeded (Redisdb *db, RobJ *key) function is located in SRC/DB.C.
/*-------------------------------------------------------------------
reading/writing a key that has expired, the lazy delete policy is triggered, and the expired key is deleted directly
Active deletion: Due to the lazy deletion policy cannot guarantee that cold data is deleted in time, so Redis will periodically proactively eliminate a batch of expired key
Active cleanup policy is triggered when current memory exceeds maxmemory limit
Passive deletionOnly when a key is manipulated (such as get) does Redis passively check if the key is out of date, de
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.